<html>
<head>
    <meta charset="UTF-8">
    <title>合同日计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/bass.css"/>
    <link rel="stylesheet" href="../../css/air/arrPay.css"/>
    <style>
        .layui-input-block{
            margin-left: 60px !important;
            margin-top: 1px;
        }
        .left{
            margin-left: 20px;
        }
    </style>
</head>

<body>
<div class="body contractDay">
    <header class="layui-nav" id="headerTop"></header>
    <div class="left_muen" id="left_menu"></div>
    <div class="content_body contractDay">
        <p class="content_title">气量管理&nbsp;&nbsp;>&nbsp;&nbsp;合同日计划</p>

        <div class="content_seach">
            <div class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label">日期</label>

                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="startTime" id="test31" placeholder="请输入起始日期">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="endTime" id="test32" placeholder="请输入结束日期">
                    </div>
                    <div class="layui-inline left">
                        <label class="layui-form-label">上报</label>
                        <div class="layui-input-block">
                            <select name="status" lay-search="">
                                <option value="">请选择是否上报</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">合计</label>-->
                    <!--<div class="layui-input-block">-->
                    <!--<input type="text" name="aggreget" placeholder="请输入合同编号" autocomplete="off" class="layui-input w30">-->
                    <!--</div>-->
                    <!--</div>-->
                </div>
                <div class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit="" lay-filter="search">
                    <i class="layui-icon">&#xe615;</i>查询
                </div>
            </div>
        </div>
        <div class="content_table">
            <div class="tabbut">
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="getCheckData"><i class="layui-icon">&#xe60a;</i>指定计划</button>
                        <button class="layui-btn layui-btn-sm" lay-event="upCheckData"><i class="layui-icon">&#xe688;</i>上报</button>
                    </div>
                </script>

            </div>
            <div class="tabTable">
                <table id="demo"  lay-filter="table" lay-data="{id:'idTest'}"></table>
                <div class="layui-table-page fr">
                    <div id="layui-table-page1"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="maTypeTemplet">
    {{#if (d.status == 0) { }}
    否
    {{# }else if(d.status == 1){ }}
    是
    {{# } }}
</script>
<script src="../../js/common/jquery-1.11.3.min.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/common/navList.js"></script>
<script src="../../js/common/ajax.js"></script>

<script>
    layui.use(['table','form','laydate'], function () {
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#test31',
            theme: 'grid',
        });
        laydate.render({
            elem: '#test32',
            theme: 'grid',
        });
        var user =  JSON.parse(window.sessionStorage.getItem('user'));
        var companyName = !user.msg.userCompanyAllTitle ? "": "&userCompanyAllTitle="+user.msg.userCompanyAllTitle;
        //初始化第一个实例
        ajaxTable({
            idNode: '#demo',
            url: 'contractdayplan/getList',
            urlParme:companyName,
            dataCols: [
                {fixed: 'status', checkbox: true},
                {field: 'organization', title: '下游组织',align: 'center'},
                {field: 'contractName', title: '合同',align: 'center'},
                {field: 'siteName', title: '站点',align: 'center'},
                {field: 'unit', title: '单位',align: 'center'},
                {field: 'forecastPlanVal', title: '预测日指定计划',align: 'center'},
                {field: 'planVal', title: '日指定计划',align: 'center'},
                {field: 'status', title: '是否已上报',align: 'center',templet:'#maTypeTemplet'},
                {field: 'planDesc', title: '备注1',align: 'center'},
            ],
            successFull:function(res, curr, count,table){

                console.log(res)
                table.on('toolbar(table)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if (obj.event == 'upCheckData') {
                        var data = checkStatus.data;
                        if (data.length == '') {
                            layer.msg('请勾选要上报的客户', {
                                icon: 6
                            });
                        } else {
                          var dataId = [];
                          var param = {};
                          $.each(data, function (i, item) {
                              dataId.push(item.id);
                          });
                          var user =  JSON.parse(window.sessionStorage.getItem('user'));
                          console.log(user)
                          if(!user.userCompanyAllTitle){
                              param.ids = dataId;
                          }else{
                              param.ids = dataId;
                              param.userCompanyAllTitle = user.userCompanyAllTitle
                          }
                          ajaxPost({
                              url: 'contractdayplan/upperData',
                              data: param,
                              successFull: function (res) {
                                  layer.msg("已成功上报", {
                                      icon: 6
                                  });
                                  updata();
                              },
                              errCallBack: function (res) {
                                  layer.msg(res.msg, {
                                      icon: 6
                                  });
                              }
                          })
                        }
                    };
                    if(obj.event == 'getCheckData'){
                        window.location.href = './contractDayAdd.html?pos=4&childPos=4'
                    }
                })
            }
        });
//        条件查询
        form.on('submit(search)', function(data){
//            data.field.devicename = !data.field.devicename?"":data.field.devicename;
            var user =  JSON.parse(window.sessionStorage.getItem('user'));
            var companyName;
            user.userCompanyAllTitle = !user.msg.userCompanyAllTitle?"":user.msg.userCompanyAllTitle;
            companyName = '&startTime='+data.field.startTime+'&endTime='+data.field.endTime+'&status='+data.field.status+'&userCompanyAllTitle='+user.userCompanyAllTitle;
            if(data.field.endTime ==''){
                companyName ='&startTime='+data.field.startTime+'&status='+data.field.status+'&userCompanyAllTitle='+user.userCompanyAllTitle;
            };
            if(data.field.startTime ==''){
                companyName ='&endTime='+data.field.endTime+'&status='+data.field.status+'&userCompanyAllTitle='+user.userCompanyAllTitle;
            };
            if(data.field.endTime ==''&&data.field.startTime ==''){
                companyName ='&status='+data.field.status+'&userCompanyAllTitle='+user.userCompanyAllTitle;
            };
             if(data.field.status == ""){
                companyName ='&startTime='+data.field.startTime+'&endTime='+data.field.endTime+'&userCompanyAllTitle='+user.userCompanyAllTitle;
            };
            ajaxTable({
                idNode: '#demo',
                url: 'contractdayplan/getList',
                urlParme:companyName,
                dataCols: [
                    {fixed: true, checkbox: true},
                    {field: 'organization', title: '下游组织',align: 'center'},
                    {field: 'contractName', title: '合同',align: 'center'},
                    {field: 'siteName', title: '站点',align: 'center'},
                    {field: 'unit', title: '单位',align: 'center'},
                    {field: 'forecastPlanVal', title: '预测日指定计划',align: 'center'},
                    {field: 'planVal', title: '日指定计划',align: 'center'},
                    {field: 'status', title: '是否已上报',align: 'center',templet:'#maTypeTemplet'},
                    {field: 'planDesc', title: '备注1',align: 'center'},
//                    {field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
                ],
                successFull: function (res, curr, count,table) {
//                    $.each($(".layui-table-main input"),function(i,item){
//                        var $_this = $(this);
//                        $.each($_this.parent().parent().siblings(),function(j,sibling){
//                            if($(sibling).attr("data-field")== 'status'){
//                                if($(this).attr("data-content") == 1){
//                                    console.log($_this)
//                                    $_this.siblings().css({display:"none"})
//                                    $_this.siblings().find("i").remove()
//                                    $_this.remove();
//                                    $(".layui-table-fixed .layui-table-body tr").eq(i).find(".laytable-cell-checkbox").css({display:"none"})
//                                }
//                            }
//                        })
//                    })
                }
            });
        })
    });
    function updata(){
        var user =  JSON.parse(window.sessionStorage.getItem('user'));
        var companyName = !user.msg.userCompanyAllTitle ? "": "&userCompanyAllTitle="+user.msg.userCompanyAllTitle;
        //初始化第一个实例
        ajaxTable({
            idNode: '#demo',
            url: 'contractdayplan/getList',
            urlParme: companyName,
            dataCols: [
                {fixed: true, checkbox: true},
                {field: 'organization', title: '下游组织', align: 'center'},
                {field: 'contractName', title: '合同', align: 'center'},
                {field: 'siteName', title: '站点', align: 'center'},
                {field: 'unit', title: '单位', align: 'center'},
                {field: 'forecastPlanVal', title: '预测日指定计划', align: 'center'},
                {field: 'planVal', title: '日指定计划', align: 'center'},
                {field: 'status', title: '是否已上报', align: 'center', templet: '#maTypeTemplet'},
                {field: 'planDesc', title: '备注1', align: 'center'},
            ],
            successFull: function (res, curr, count,table){
//                $.each($(".layui-table-main input"),function(i,item){
//                    var $_this = $(this);
//                    $.each($_this.parent().parent().siblings(),function(j,sibling){
//                        if($(sibling).attr("data-field")== 'status'){
//                            if($(this).attr("data-content") == 1){
//                                console.log($_this)
//                                $_this.siblings().css({display:"none"})
//                                $_this.siblings().find("i").remove()
//                                $_this.remove();
//                                $(".layui-table-fixed .layui-table-body tr").eq(i).find(".laytable-cell-checkbox").css({display:"none"})
//                            }
//                        }
//                    })
//                })
            }
        })
    }
</script>
</body>
</html>